<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;"/>

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
import {getAllSubjectToTree} from "@/api/edu/subject";

export default {

  data() {
    return {
      filterText: '',
      //数据集合
      data2: [],
      //节点名
      /*defaultProps: {
        children: 'children',
        label: 'label'
      }*/
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },
  created() {
    this.getAllSubjectToTree();
  },
  methods: {
    //搜索功能，
    filterNode(value, data) {
      if (!value) return true;
      //不区分大小写
      return data[this.defaultProps.label].toLowerCase().indexOf(value.toLowerCase()) !== -1
    },
    getAllSubjectToTree() {
      getAllSubjectToTree().then(ser => {
        this.data2 = ser.data.subjectTreeVoList;
      })
    }
  }
}
</script>

